var config = require('../../../config.js')
var http = require('../../../utils/httpHelper.js')
Page({
  data: {
    userName:'',
    noSave:true
  },
  //事件处理函数
  onLoad: function () {
    var that = this;
    let userInfo = wx.getStorageSync('user');
    that.setData({userName:userInfo.userName});
  },
  nameinput:function(e) {
    this.setData({      
      userName: e.detail.value,
      noSave:false
    })
  },
  formSubmit: function (e){
    //提交表单
    let userInfo = wx.getStorageSync('user');
    var val = e.detail.value;
    if(val.userName != ''){
      var data = {userId:userInfo.userId,userName:val.userName}
      http.httpPutForm(config.clubApi.putUserName,data,function(res){
        if(res.code == '200') {
          userInfo.userName = val.userName;
          wx.setStorageSync('user', userInfo);
          wx.navigateBack();
          console.log("修改姓名成功");
        }else {
          console.log("修改姓名失败");
        }
      });
    }
  }
})